path: do not recurse into hidden/dot directories
authorLuca Bruno <lucab@debian.org>
Sat, 29 Aug 2015 09:20:13 +0000 (11:20 +0200)
committerLuca Bruno <lucab@debian.org>
Tue, 1 Sep 2015 16:54:14 +0000 (18:54 +0200)
Cargo recursively looks for TOML manifest into child directories,
sometimes getting into unrelated files when exploring hidden
directories (eg. quilt .pc).

This commit lets cargo skip dot directories, to partially avoid
the issues described in #1423.

Signed-off-by: Luca Bruno <lucab@debian.org>
src/cargo/ops/cargo_read_manifest.rs
src/cargo/sources/path.rs
tests/test_cargo_compile.rs

index 123a92039c1e9a9b43db4a58dea7783e1fcf6cf2..741445510b9447693c0727aa1944615f053f1186 100644 (file)
@@ -43,8 +43,9 @@ pub fn read_packages(path: &Path, source_id: &SourceId, config: &Config)
     try!(walk(path, &mut |dir| {
         trace!("looking for child package: {}", dir.display());
 
-        // Don't recurse into git databases
-        if dir.file_name().and_then(|s| s.to_str()) == Some(".git") {
+        // Don't recurse into hidden/dot directories
+        let name = dir.file_name().and_then(|s| s.to_str());
+        if name.map(|s| s.starts_with(".")) == Some(true) {
             return Ok(false)
         }
 
index 0e3668b42b4a2063dad13bdf48fd977b1abfdbd0..0bca3de26f58d667d4542d05335859646c60aac4 100644 (file)
@@ -255,11 +255,16 @@ impl<'cfg> PathSource<'cfg> {
         }
         for dir in try!(fs::read_dir(path)) {
             let dir = try!(dir).path();
-            match (is_root, dir.file_name().and_then(|s| s.to_str())) {
-                (_,    Some(".git")) |
-                (true, Some("target")) |
-                (true, Some("Cargo.lock")) => continue,
-                _ => {}
+            let name = dir.file_name().and_then(|s| s.to_str());
+            // Skip dotfile directories
+            if name.map(|s| s.starts_with(".")) == Some(true) {
+                continue
+            } else if is_root {
+                // Skip cargo artifacts
+                match name {
+                    Some("target") | Some("Cargo.lock") => continue,
+                    _ => {}
+                }
             }
             try!(PathSource::walk(&dir, ret, false, filter));
         }
index ca147db349b0f4cfaecdd530229f8224b60ad23e..62dfd76f2c2327bbe99c400c208c7b2f3dd7c145 100644 (file)
@@ -1828,6 +1828,24 @@ test!(ignore_dotfile {
                 execs().with_status(0));
 });
 
+test!(ignore_dotdirs {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/bin/a.rs", "fn main() {}")
+        .file(".git/Cargo.toml", "")
+        .file(".pc/dummy-fix.patch/Cargo.toml", "");
+    p.build();
+
+    assert_that(p.cargo("build"),
+                execs().with_status(0));
+});
+
+
 test!(custom_target_dir {
     let p = project("foo")
         .file("Cargo.toml", r#"